/**
 *  @file Node.h
 */
#ifndef _XMLNODE_H_
#define _XMLNODE_H_

#include "../../common/BaseObject.h"
#include "../../text/CFString.h"
#include "../../collections/tree/MCTreeNode.h"
#include "../../collections/LinkedHashtableT.h"

namespace cppflib
{

namespace xml
{

namespace dom
{

/**
 *  A class which represents a node in a DOM tree.
 *  This is *not* equivalent to that in W3C DOM node. Those node can be differentiated
 *  as Element, Entity, text node and so on.
 *
 *  This Node contains all of the below components in one object:
 *     1) node name (or element name)
 *     2) attribute list (may or may not present)
 *     3) text content (may or may not present)
 *     4) pointer to parent and child nodes
 *  
 *  For example, all information of the below XML element are contained in one Node object
 *
 *     <hello attr1="ok">some text</hello>
 *  or
 *     <hello attr2="no" />
 */
class _DLLAPI Node : public collections::tree::MCTreeNode
{
private:
    CFString * pTextContent;
    collections::LinkedHashtableT<CFString, CFString> *pAttrs;

protected:
	Node(void);

public:
    explicit Node(CFString *pKey);
	virtual ~Node(void);
    /////// derived from MCTreeNode
    virtual bool AddChild(MCTreeNode * pChild);
    virtual bool DeleteChild(const BaseObject &key);
    virtual bool IsAncestor(MCTreeNode *pNode);
    virtual bool Move(MCTreeNode *pNode);
    virtual void DetachFromTree();

    /////// Newly added
    const collections::LinkedHashtableT<CFString, CFString> * GetAttributes();
    void SetAttributes(const collections::LinkedHashtableT<CFString, CFString> & attributes);
    const CFString * GetNodeName();
    const CFString * GetNodeTextContent();
    void AppendTextContent(const CFString &text);
    bool HasAttributes();
    bool HasChildNodes();
    Node * GetChildNodeByTagName(pcwstr_t tagName);
};

} // end of namespace dom

} // end of namespace xml

} // end of namespace cppflib


#endif
